import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class PersonTest6 {
    public static void main(String[] args) {


        Class clz = null;
        try {
            clz = Class.forName("reflect.entity.Person");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        Constructor c1 = null;
        try {
            c1 = clz.getDeclaredConstructor();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        Object obj = null;
        try {
            obj = c1.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        System.out.println(obj);

        Constructor c2= null;
        try {
            c2 = clz.getDeclaredConstructor(String.class);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        c2.setAccessible(true);
        try {
            obj=c2.newInstance("New Preson");
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        System.out.println(obj);

        Constructor c3= null;
        try {
            c3 = clz.getDeclaredConstructor(String.class,String.class,String.class);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        c3.setAccessible(true);
        try {
            obj=c3.newInstance("New Person","beijing","Hello!");
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        System.out.println(obj);
    }
}
